package trabajoISW2.presentation.shared;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import trabajoISW2.domain.implementations.Book;
import trabajoISW2.domain.implementations.Subject;

public class SubjectMapper {

	
	public static SubjectDTO createDTO (Subject s){
		SubjectDTO dto = new SubjectDTO(s.getName(), null);
		Iterator<Book> it = s.getBooks().iterator();
		BookDTO bdto;
		Book b;
		while (it.hasNext()){
			b= it.next();
			bdto = BookMapper.createDTO(b);
			dto.getBooks().add(bdto);
		}
		return dto;
	}
	
	public static Subject updateDomainObject (SubjectDTO dto){
		Subject s = new Subject (dto.getSubject(), null);
		Iterator<BookDTO> it = dto.getBooks().iterator();
		BookDTO bdto;
		Book b;
		while (it.hasNext()){
			bdto= it.next();
			b = BookMapper.updateDomainObject(bdto);
			s.addBook(b);
		}
		return s;
	}
}
